package cn.edu.nju.software.zp13.client.assignment4.sax.scoreListXml;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import cn.edu.nju.software.zp13.client.assignment3.xmlGenerator.XmlContentStrategy;
import cn.edu.nju.software.zp13.client.assignment3.xmlNodeEntity.util.ScoreType;
import cn.edu.nju.software.zp13.client.assignment4.sax.CourseScoreSelector;
import cn.edu.nju.software.zp13.client.assignment4.sax.xmlNodeEntity.CourseScoreList;

/**
 * input scoreListXml1 and generate scoreListXml2's DOM
 * 
 * @author Ivan
 *
 */
public class ScoreList2Xml extends XmlContentStrategy {
	private CourseScoreList scoreList;

	public ScoreList2Xml(String scoreList1XmlPath) {
		CourseScoreSelector c = new CourseScoreSelector();
		scoreList = new CourseScoreList();
		// select failed CourseScore
		scoreList.setCs(c.selectRequiredCourseScore(cs -> cs.getScore().getScore() < 60 && cs.getSt() == ScoreType.总评成绩,
				scoreList1XmlPath));
		seedNamespace();
	}

	@Override
	protected void processDom(Document dom) {
		Node node = scoreList.toXmlNode(dom);
		dom.appendChild(node);
		Element root = (Element) dom.getChildNodes().item(0);
		addNamespace(root);
	}

	private void seedNamespace() {
		namespace.put("xmlns", "http://jw.nju.edu.cn/schema");
		namespace.put("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
		namespace.put("xsi:schemaLocation", "http://jw.nju.edu.cn/schema ScoreList.xsd");
	}

}
